/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.awt.Graphics;

public class Wire implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Output fromPin = null;
	private Input inPin = null;
	private Integer outputValue;
	private int index;
	private Integer actualValue =null;


	private int x1;
	private int y1;
	private int x2;
	private int y2;

	public Wire(int x1, int y1, int x2, int y2) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;

	}

	public Wire() {
		this.x1 = 0;
		this.y1 = 0;
		this.x2 = 0;
		this.y2 = 0;
	}

	public void setInput(Output pin) {
		fromPin = pin;
	}
	
	public void setIndex(int i) {
		index = i;
	}
	
	public int getIndex() {
		return index;
	}
	
	public Integer getSignal(Integer input){
		this.outputValue = input;
		return this.outputValue;
	}

	public void setPin(Input pin) {
		inPin = pin;
	}
	
	public Input getPin(){
	return inPin;
	}

	public Output getInput() {
		return fromPin;
	}

	public Input getOutput() {
		return inPin;
	}

	public void setNewEnd() {
		this.x2 = inPin.getX() + 2;
		this.y2 = inPin.getY() + 2;
	}

	public void setNewStart(int x, int y) {
		this.x1 = fromPin.getX() + 2;
		this.y1 = fromPin.getY() + 2;
	}

	public Integer getValue(int index) {
		try {
			return fromPin.getValue(index);
		} catch (Exception e) {
			return null;
		}

	}
	
	
	public Integer getValue() {
		return actualValue;
	}

	public void draw(final Graphics g) {
		g.drawLine(x1, y1, x2, y2);
	}
}
